package com.leeoohoo.dto;

import com.leeoohoo.utils.UserStateUtils;
import lombok.Data;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.util.Collection;
import java.util.List;

@Data
public class MyUserDetails implements UserDetails {

    private Long id;

    private String username;

    private String password;

    private Long state;

    private List<AuthRole> roleList;

    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return roleList;
    }

    @Override
    public String getPassword() {
        return this.password;
    }

    @Override
    public boolean isAccountNonExpired() {
        return UserStateUtils.toUserStateDTO(this.state).getAccountNonExpired();
    }

    @Override
    public boolean isAccountNonLocked() {
        return UserStateUtils.toUserStateDTO(this.state).getAccountNonLocked();
    }

    @Override
    public boolean isCredentialsNonExpired() {
        return UserStateUtils.toUserStateDTO(this.state).getCredentialsNonExpired();
    }

    @Override
    public boolean isEnabled() {
        return UserStateUtils.toUserStateDTO(this.state).getEnabled();
    }
}
